package com.his.dictrole.service.Imp;

import com.his.dictrole.dao.DictRoleEmpMapper;
import com.his.dictrole.entity.DictRoleEmp;
import com.his.dictrole.service.DictRoleEmpService;
import com.his.dictrole.vo.DictRoleEmpVo;
import com.xiao.common.util.WorkIdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author xiaoxiaoping
 * @Date 2020/3/9 19:02
 * @Version 1.0
 */
@Service
public class DictRoleEmpServiceImpl implements DictRoleEmpService {

    @Autowired
    private DictRoleEmpMapper dictRoleEmpMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<DictRoleEmp> qureyByEmpId(String empId)  {
       return dictRoleEmpMapper.selectByEmp(empId);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteByEmpId(String empId) {

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void save(DictRoleEmpVo dictRoleEmpVo) {
        dictRoleEmpMapper.deleteByEmpId(dictRoleEmpVo.getEmpId());
        String[] roleIds = dictRoleEmpVo.getRoleIds();
        for(String roleId : roleIds){
            DictRoleEmp dictRoleEmp = new DictRoleEmp();
            dictRoleEmp.setId(WorkIdUtil.nextId());
            dictRoleEmp.setRoleId(roleId);
            dictRoleEmp.setEmpId(dictRoleEmpVo.getEmpId());
            dictRoleEmpMapper.insert(dictRoleEmp);
        }
    }
}
